from typing import List
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel
from PyQt5.QtCore import Qt, QTimer


class SpiritView(QWidget):
    def __init__(self, items: List[str]):
        super().__init__()
        self._items = items
        self._idx = 0
        layout = QVBoxLayout(self)
        self.label = QLabel(items[0] if items else "")
        self.label.setAlignment(Qt.AlignCenter)
        self.label.setStyleSheet("QLabel { font-size: 22px; }")
        layout.addWidget(self.label)
        self.timer = QTimer(self)
        self.timer.setInterval(2000)
        self.timer.timeout.connect(self._next)
        self.timer.start()

    def _next(self):
        if not self._items:
            return
        self._idx = (self._idx + 1) % len(self._items)
        self.label.setText(self._items[self._idx])

    def set_data(self, items: List[str]):
        self._items = items
        self._idx = 0
        self.label.setText(items[0] if items else "")

